package com.wu.springbootmqproducer.Config;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class MyReturnListener implements RabbitTemplate.ReturnCallback {


    @Autowired
    private AmqpTemplate amqpTemplate;


    @Autowired
    private RabbitTemplate rabbitTemplate;
    @PostConstruct
    public void init(){
        rabbitTemplate.setReturnCallback(this);
    }

    /**
     *
     * @param message 消息对象
     * @param i 错误码
     * @param s 错误信息
     * @param s1 交换机
     * @param s2 路由key
     */
    @Override
    public void returnedMessage(Message message, int i, String s, String s1, String s2) {
        System.out.println(message);
        System.out.println(i);
        System.out.println(s);
        System.out.println(s1);
        System.out.println(s2);

        amqpTemplate.send(s1,s2,message);
    }
}
